class SwitchButton extends egret.DisplayObjectContainer {
	private skin:egret.MovieClip;
	public constructor() {
		super();
		mouse.setButtonMode(this, true);
		this.touchEnabled=true;
	}
	//从资源创建按钮皮肤
	public createSkinByName(file:string,name:string){
		let skin=this.skin=Tools.createMovieClipByName(file,name);
		this.addChild(skin);
		skin.gotoAndStop(1);
	}
	//从影片剪辑创建按钮皮肤
	public createMovieClipSkin(mc:egret.MovieClip){
		let skin=this.skin=mc;
		this.addChild(skin);
		skin.gotoAndStop(1);
		//mouse.setButtonMode(skin, true);
	}
	//
	public enable(value:Boolean){
		if(value){
			this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouchTapHandler,this);
		}else{
			this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouchTapHandler,this);
		}
	}
	//
	private onTouchTapHandler(e:egret.TouchEvent){
		if(this.skin.currentFrame==1){
			this.skin.nextFrame();
		}else{
			this.skin.gotoAndStop(1);
		}
	}

	public isOn():Boolean{
		if(this.skin.currentFrame==1){
			return true;
		}else{
			return false;
		}
	}

	public setState(b:Boolean):void{
		if(b){
			this.skin.gotoAndStop(1);
		}else{
			this.skin.gotoAndStop(2);
		}
	}
}